<?php 
/**
 * 场景： 数据库连接
 */

class Mysql
{
	private static $conn;

	private function __construct(){
		self::$conn = mysqli_connect('localhost','root','root');
	}

	public static function getInstance(){
		if (!$self::$conn instanceof self) {
			self::$conn = new self;
		}

		return self::$conn;
	}

	// 防止对象被复制
	private function __clone(){
		trigger_error('clone is not allowed');
	}

	// 防止反序列化后创建对象
	private function __wakeup(){
		trigger_error('Unserialize is not allowed');
	}
}

$mysql = Mysql::getInstance();